<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/22
 * Time: 14:30
 */

namespace App\Transformers;


use App\Models\Saidan;
use League\Fractal\TransformerAbstract;

class SaidanTransformer extends TransformerAbstract
{

    protected $availableIncludes = ['user'];

    public function transform(Saidan $saidan){
        return[
            'id'=>$saidan->id,
            'user_id'=>$saidan->user_id,
            'good_id'=>$saidan->good_id,
            'good_name'=>$saidan->good_name,
            'contents'=>$saidan->contents,
            'is_pre'=>$saidan->is_pre,
            'created_at' => $saidan->created_at->toDateTimeString(),
//            'updated_at' => $saidan->updated_at->toDateTimeString(),
        ];
    }

    public function includeUser(Saidan $saidan){

        return $this->item($saidan->user,new UsersTransformer(false));


    }
}